#ifndef _AX_FD_H
#define _AX_FD_H

#include "com.h"
#include <stdbool.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif

#define AX_FD_CHECK 1

#define AX_FD_READ 0x0001
#define AX_FD_WRITE 0x0002
#define AX_FD_EXCEPT 0x0004

typedef struct ax_fd ax_fd;
typedef int (*ax_fd_cb_t)(ax_fd* fd, unsigned int what);
struct ax_fd
{
    int          fd;
    unsigned int when;
    ax_fd_cb_t   cb;
    void*        data;              // attached data
    double       last_active_time;  // last recv data
};

ax_fd* ax_fd_create(int fd, unsigned int when, ax_fd_cb_t cb, void* data);
bool   ax_fd_is_valid(ax_fd*);
void   ax_fd_destroy(ax_fd* f);
void   ax_fd_close(ax_fd* fd);

#ifdef __cplusplus
}
#endif

#endif /* defined(_AX_FD_H) */
